package NW_MC;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import NWPackage.PairPreferdCandidateCell;
import Readers.InputsReader;
//import Readers.StaticInputs;
//import Readers.StaticInputs3cands;

public class CandidateMinMax {
	//Map of <Candidate Name, Min&Max Value>
	private Map<String,MinMaxCell> cells;
	
	public CandidateMinMax()
	{
		this.cells = new HashMap<String, MinMaxCell>();
		
	}
	public CandidateMinMax(Map<String,MinMaxCell> cells)
	{
		this.cells = cells;
	}
	
	public CandidateMinMax(List<String> candidates)
	{
		this.cells = new HashMap<String, MinMaxCell>();
		for (String candidate : candidates) {
			cells.put(candidate, new MinMaxCell(candidates.size()));
		}
	}
	 public void setQuery(PairPreferdCandidateCell query)
	 {
		 //check who is big and small
		 String[] candidates = query.getCandidates();
		 String preffered = query.getPrefered_C();
		 
		 String big;
		 String small;
		 
		 if (candidates[0] == preffered){
			 big = candidates[0];
			 small= candidates[1];
		 }
		 else
		 {
			 big = candidates[1];
			 small = candidates[0];
		 }
		 //X>Y --> min(x)+1, max(y)-1
		 int minPlusOne = this.cells.get(big).getMin()+1;
		 int maxMinusOne = this.cells.get(small).getMax()-1;
	//	 System.out.print("borda: " + InputsReader.getBordaMaxValue() + " " +InputsReader.getBordaMinValue() );
		 if (minPlusOne<=InputsReader.getBordaMaxValue()){
			 this.cells.get(big).setMin(minPlusOne);
	//		 System.out.print(" big_item="+ big + "  min=" + (minPlusOne));
		 }
		 if(maxMinusOne >= InputsReader.getBordaMinValue()){
			 this.cells.get(small).setMax(maxMinusOne);
		//	 System.out.println(" small_item=" + small + "  max=" + (maxMinusOne));
		 }
	 }
	public MinMaxCell getCellByCandidateName(String candidate) {
		return this.cells.get(candidate);
	}

	
}
